package com.session01;

public class Demo {
    public static void main(String[] args) {
        Animals[] animals = new Animals[4];
        Animals bird1 = new Bird();
        Animals horse1 = new Horse();
        Animals bird2 = new Bird();
        Animals horse2 = new Horse();
        animals[0] = bird1;
        animals[1] = horse1;
        animals[2] = bird2;
        animals[3] = horse2;

        for (int i = 0; i < animals.length; i++) {
            animals[i].run();
        }
    }
}

class Animals {
    public void run() {
        System.out.println("动物都要跑");
    }
}

class Bird extends Animals {
    public void run() {
        System.out.println("小鸟会飞");
    }
}

class Horse extends Animals {
    public void run() {
        System.out.println("小马会跑");
    }
}